﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<script src="~/lib/layui/layui.js"></script>
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <div class="layui-form">
        <div class="layui-row layui-col-space16">
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-group">
                        <div class="layui-input-split layui-input-prefix">
                            工作站
                        </div>
                        <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="Productionname" />
                        <div class="layui-btn-container">

                            <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-custom">
                                <span class="layui-badge-dot"></span> 选择工作站
                            </button>


                            @*   <button type="button" class="layui-btn layui-btn-radius" lay-on="test-iframe-curl">工作站选择</button> *@
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-group">
                        <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="ProcessName">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排产数量</label>
        <div class="layui-input-block">
            <input type="number" name="price_min" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number" style="width:200px" id="Productionnum">
        </div>
    </div>
    <div class="layui-form">
        <div class="layui-row layui-col-space16">
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-group">

                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <input type="date" class="layui-input" id="StartTime1" placeholder="yyyy-MM-dd">
                        </div>


                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-group">
                        <div class="layui-input-split layui-input-prefix">
                            生产时长
                        </div>
                        <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="ProductionTime">
                        @*  <input type="text" placeholder="请输入" class="StartTime" style="width:200px" id="ProductionTime" onchange="Trigger()"> *@
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-group">

                        <label class="layui-form-label">完成时间</label>
                        <div class="layui-input-inline">
                            <input type="date" class="layui-input" id="FinshTime" placeholder="yyyy-MM-dd">
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-btn-container" style="float:left">
        <button type="button" class="layui-btn layui-btn-radius" onclick="Stach()">修改</button>
    </div>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
    <script>

        $(()=>{


            DataBack()

        })
        var processid=""
        var QuantityProduced = "";
        //生产任务反填
        function DataBack() {


            processid = location.href.split("=")[1];


            console.log(processid);
            $.ajax({

                url: '@ViewBag.FoundationRead' + '/api/Production/SchedulingDisplayBack',
                type: "post",
                data: JSON.stringify({ productionid: processid }),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    $('#Productionname').val(res.data[0].productionname);
                    $('#Productionnum').val(res.data[0].productionnum);
                    $('#StartTime1').val(res.data[0].startTime);
                    $('#ProductionTime').val(res.data[0].productionTime);
                    $('#FinshTime').val(res.data[0].finshTime);
                    QuantityProduced=res.data[0].quantityProduced
                }
            })
        }
          var TaskName="";
          
          function Stach() {

              var date = {
                productionid: processid,
                Productionname:$('#Productionname').val(),
                Productionnum:$('#Productionnum').val(),
                StartTime:$('#StartTime1').val(),
                ProductionTime:$('#ProductionTime').val(),
                FinshTime:$('#FinshTime').val(),
                TaskNumber:"MG" + Math.random().toString().substring(2, 6),
                TaskName:"78",
                QuantityProduced:QuantityProduced,
              };
              console.log(date);

              $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/Jocker/SchedulingDisplayUpdate",
                  type: 'post',
                  data: JSON.stringify(date),
                  dataType: "json",
                  contentType: "application/json",
                  success: res => {
                      if (res.code > 0) {
                          alert("修改成功");
                          // location.href = "../Document/index";
                        layer.close(layer.index);
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }
                      else {

                      }

                  }

              })



          }
          layui.use(function () {
              var $ = layui.$;
              var layer = layui.layer;
              var util = layui.util;
              var form = layui.form;
              var table = layui.table
              // 事件

              util.on('lay-on', {
                  'test-page-custom': function () {
                      layer.open({
                          type: 1,
                          area: '700px',
                          resize: false,
                          shadeClose: true,
                          title: 'demo : 工作站选择',
                          content: `
                               <div>
                                   <table class="layui-hide" id="ID-table-demo-data"></table>
                               </div>
                              <div>
                                  <div class="layui-btn-container">
                                  <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-logins" style="width:100px" >确定</button>
                                  </div>
                             </div> `,
                          success: function () {
                              // 对弹层中的表单进行初始化渲染
                              form.render();
                              // 表单提交事件
                              form.on('submit(demo-login)', function (data) {
                                  var field = data.field; // 获取表单字段值
                                  // 显示填写结果，仅作演示用
                                  layer.alert(JSON.stringify(field), {
                                      title: '当前填写的字段值'
                                  });

                                  // 此处可执行 Ajax 等操作
                                  // …
                                  return false; // 阻止默认 form 跳转
                              });


                              StashHtml()
                              //仓库显示
                              function StashHtml() {


                                  $.ajax({

                                      url:'@ViewBag.FoundationRead'+ "http://localhost:5043/api/Production/WorkStationHtml",
                                      data: JSON.stringify({}),
                                      type: "post",
                                      async: false,
                                      dataType: "json",
                                      contentType: "application/json",
                                      success: res => {

                                          console.log(res.date)
                                          layui.use('table', function () {
                                              var table = layui.table;

                                              // 已知数据渲染
                                              var inst = table.render({
                                                  elem: '#ID-table-demo-data',
                                                  cols: [[ //标题栏
                                                      { type: 'checkbox', title: '复选框', fixed: true }, // 单选框
                                                      { field: 'workStations', title: '工作站编号', width: 200, sort: true },
                                                      { field: 'workStationName', title: '工作站名称', width: 200 },
                                                      { field: 'workStationlocation', title: '工作站地点', width: 200 },
                                                      { field: 'workshopName', title: '所在车间名称', width: 200 },
                                                      { field: 'processName', title: '所属工序', width: 200 },
                                                      { field: 'workStationRemarks', title: '备注', width: 200 },
                                                  ]],
                                                  data: res.data,
                                                  //skin: 'line', // 表格风格
                                                  //even: true,
                                                  page: true, // 是否显示分页
                                                  limits: [5, 10, 15],
                                                  limit: 5 // 每页默认显示的数量
                                              });
                                          });
                                      }

                                  })





                              }
                              var getid = 0;

                              // 触发表格复选框选择
                              table.on('checkbox(ID-table-demo-data)', function (obj) {
                                  getid = obj.data.workid
                                 goback()
                                  console.log(getid);
                              });
                              form.on('submit(demo-logins)', function (data) {

                                    layer.close(layer.index); // 关闭当前最新弹层

                                  return false;

                              });

                              function goback()
                              {
                                  $.ajax({
                                    url: '@ViewBag.FoundationRead' + "/api/Production/WorkStationback",
                                      data: JSON.stringify({Workid:getid}),
                                      type: "post",
                                      async: false,
                                      dataType: "json",
                                      contentType: "application/json",
                                      success: res => {
                                          console.log(res.data);

                                           $("#Productionname").val(res.data[0].workStationName)
                                           QuantityProduced=res.data[0].workStations
                                      }
                                  })


                              }
                          }
                      });
                  }
              })
          })
    </script>
</body>
</html>

